﻿using Dolany.UtilityTool;
using Microsoft.AspNetCore.Mvc;
using Missbot.Common.Net;
using Missbot.Core.Cache;
using Newtonsoft.Json;

namespace Missbot.Admin.Controllers
{
    [Route("[controller]/[action]")]
    public class WeiboBotController : APIBaseController
    {
        public class RefreshCookieReq
        {
            public CookieModel[] Cookies { get; set; }

            public bool IsValid => !Cookies.IsNullOrEmpty();
        }

        [HttpPost]
        public IActionResult RefreshCookie(RefreshCookieReq req)
        {
            if (!req.IsValid)
            {
                return new JsonResult(new {code = -1, msg = "req invalid"});
            }

            var config = GlobalVarDA.Get("WeiboBotCookie");
            config.Value = JsonConvert.SerializeObject(req.Cookies);
            config.Update();

            return new JsonResult(new {code = 1});
        }

        [HttpPost]
        public IActionResult AddBot(AIModule.Schedulers.WeiboBot.WeiboBot bot)
        {
            // todo
            return default;
        }
    }
}